package com.cqcj.login.web;

import com.cqcj.login.pojo.User;
import com.cqcj.login.service.RegisterService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/selectUserServlet")
public class SelectUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取参数
        RegisterService registerService = new RegisterService();//获取mapper

        String username = request.getParameter("username");
        if(username != null){
            User user = registerService.selectByUsername(username);
            if(user != null){
                request.setAttribute("err_msg","用户名已被占用");
                response.getWriter().write("true");
            }
        }
    }
}
